package jrain.iot.server.mqtt.business;

import jrain.fw.core.business.Business;
import jrain.fw.core.business.BusinessMethod;
import jrain.fw.core.business.BusinessRequest;
import jrain.fw.core.business.BusinessResponse;
import jrain.fw.core.log.Logger;
import jrain.fw.core.log.LoggerFactory;
import jrain.iot.server.mqtt.consts.MqttConst;
import jrain.utils.consts.BaseConst;
import jrain.utils.lang.StringUtils;

@Business(name = "MqttSimpleMsgService")
public class MqttSimpleMsgService {

	private static Logger logger = LoggerFactory.getLogger(MqttSimpleMsgService.class);

	@BusinessMethod()
	public BusinessResponse publish(BusinessRequest request) {
		BusinessResponse response = new BusinessResponse();
		String userName = StringUtils.trimNull(request.getData(MqttConst.USER_NAME));
		byte[] bytes = (byte[]) request.getData(MqttConst.MSG_DATA);
		String msg = new String(bytes, BaseConst.UTF8);
		logger.info(request, "username={},msg={}", userName, msg);
		return response;
	}
}
